<include file="Forum:header"/>
<body>
<div class="talk-wrap talk-detail-wrap" style="margin-bottom: 54px;">
    <header class="talk-header talk-detail-header"><span class="iconfont go-back"></span>
        <p class="text-center">主题详情</p>
    </header>
    <div class="talk-main talk-detail-main">
        <section class="talk-item">
            <article>
                <div class="talk-author">
                    <div class="table-mode">
                        <div class="table-cell"><img src="{BEESCRM:$data['avatar']}" class="avatar"></div>
                        <div class="table-cell">
                            <div class="nickname">{BEESCRM:$data['real_name']}</div>
                            <div class="time">{BEESCRM:$data['create_time']|date="m-d H:i",###}</div>
                        </div>
                        <if condition="$data['self'] eq 'yes'">
                        <div class="table-cell delete-btn"><span class="iconfont icon-shanchu"></span><span class="report">删除</span></div>
                        <else />
                        <div class="table-cell" id="report" data-postid="882"><span class="iconfont icon-icon"></span><span class="report">举报</span></div>
                        </if>
                    </div>
                </div>
                <div class="talk-content">
                    <p>{BEESCRM:$data['content']}</p>
                    <div class="thumb">
                        <volist name="data.ForumPostImage" id="vo">
                        <img src="{BEESCRM:$vo['url']}">
                        </volist>
                    </div>
                    <volist name="data.reply_list" id="vo" key="k">
                    <div class="reply-wrap">
                        <div class="reply talk-author">
                            <div class="table-mode">
                                <div class="table-cell"><img src="<if condition="$vo['sub_avatar']">{BEESCRM:$vo['sub_avatar']}<else />{BEESCRM:$vo['avatar']}</if>" class="avatar"></div>
                                <div class="table-cell">
                                    <div class="nickname clearfix">
							            <if condition="$vo['self'] eq 'no'">
								            <span class="pull-left"><if condition="$vo['sub_real_name']">{BEESCRM:$vo['sub_real_name']}<else />{BEESCRM:$vo['real_name']}</if>
									            <span class="reply-role reply-tag">回复</span>
									            <span class="feedback-role">{BEESCRM:$data['real_name']}</span>
								            </span>
							            <else />
							            	<span class="pull-left">{BEESCRM:$vo['sub_real_name']}
									            <span class="reply-role reply-tag">(楼主)</span>
								            </span>
							            </if>
                                        <div class="time pull-right">{BEESCRM:$vo['create_time']|date="m-d H:i",###}</div>
                                    </div>
                                    <div class="reply-content">{BEESCRM:$vo['content']}</div>
                                    <div class="reply-current">
                                        <if condition="$vo['sub_forum_id']">
                                        <span class="department"><span class="iconfont icon-yonghu"></span><span class="report">监控部</span></span>
                                        </if>
                                        <span class="like-btn" id="num_{BEESCRM:$k}" data-post_id="{BEESCRM:$vo['post_id']}" data-like="{BEESCRM:$vo['like']}" data-num="{BEESCRM:$k}"><span class="iconfont icon-zan"></span><span class="num">{BEESCRM:$vo['like_num']}</span></span>
                                        <span class="reply-btn zh-control" data-user_id="{BEESCRM:$vo['user_id']}"><span class="iconfont"></span><span class="reply-btn">回复</span></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    </volist>
                </div>
            </article>
        </section>
    </div>
</div>
<div class="talk-detail-action" style="display: block;">
    <div class="action-wrap">
        <div class="table-mode">
            <div class="table-cell" id="watch">
                <div class="action">
                    <span class="iconfont <if condition="$subscribe">isAction</if>"></span>
                    <span class="describ <if condition="$subscribe">isAction</if>">关注</span>
                </div>
            </div>
            <div class="table-cell" id="comments">
                <div class="action" id="reply"><span class="iconfont"></span><span class="describ">评论</span></div>
            </div>
            <div class="table-cell" id="like_num">
                <div class="action">
                    <span class="iconfont <if condition="$like">isAction</if>"></span>
                    <span class="describ <if condition="$like">isAction</if>" id="likenum">{BEESCRM:$data['like_num']}</span>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="subscribe" value="{BEESCRM:$subscribe}">
<input type="hidden" id="like" value="{BEESCRM:$like}">
<input type="hidden" id="post_id" value="{BEESCRM:$data['post_id']}">
<input type="hidden" id="forum_id" value="{BEESCRM:$forum_id}">
<include file="Forum:commonjs"/>
<script>
    $(function(){
        FastClick.attach(document.body);
        //评论
        $(document).on('click', '#comments', function () {
            $('.talk-detail-wrap, .talk-detail-action').hide();
            $('.add-reply').removeClass('hide');
        });
    });
    $('#reply').click(function(){
    	var url = '{BEESCRM::U('base/railwayForum/reply',array('forum_id' => $forum_id, 'user_id' => $data['user_id'], 'post_id' => $data['post_id'], 'user_id' => $data['user_id']))}';
    	location.href = url;
    });
    
    //回复点赞
    $('.like-btn').click(function(){
    	var post_id = $(this).data('post_id');
    	var like = $(this).attr('data-like');
    	var num = $(this).data('num');
    	$.post('{BEESCRM::U('base/forum/doGetLike',array('forum_id' => $forum_id))}',{'post_id':post_id,'like':like,'num':num},function(data){
    		if(data.status == 'S'){
    			var obj = $("#num_"+data.num);
				like_num = obj.children('.num').html();
				if(data.like == 1){
					obj.attr('data-like',0);
					obj.children('.num').html(--like_num);
				}else {
					obj.attr('data-like',1);
					obj.children('.num').html(++like_num);
				}
				$.toast('success',data.message);
			}else {
				$.toast('error',data.message);
			}
    	},'json');
    });
    
    //回复
    $('.zh-control').click(function(){
    	var forum_id = $('#forum_id').val();
    	var user_id = $(this).data('user_id');
    	var post_id = $('#post_id').val();
    	var url = '/base/railwayForum/reply/forum_id/' + forum_id + '/post_id/' + post_id;
    	if(user_id){
    		url += '/user_id/' + user_id;
    	}
    	location.href = url;
    });
    
    //关注
    $('#watch').click(function(){
    	var post_id = $('#post_id').val();
    	var subscribe = $('#subscribe').val();
    	$.ajax({
    		type:'post',
    		url:'{BEESCRM::U('base/forum/doGetSubscribe',array('forum_id' => $forum_id))}',
    		data:{'post_id':post_id,'subscribe':subscribe},
    		dataType:'json',
    		success:function(data){
    			if(data.status == 'S'){
    				if(data.subscribe == 1){
    					$('#subscribe').val(0);
    					$('#watch div').children().removeClass('isAction');
    				}else {
    					$('#subscribe').val(1);
    					$('#watch div').children().addClass('isAction');
    				}
    				$.toast('success',data.message);
    			}else {
    				$.toast('error',data.message);
    			}
    		},
    		error:function(){
    			$.toast('error','通讯错误');
    		},
    	});
    });
    
    $('.go-back').click(function(){
		history.back();
	});
    
    //点赞
    $('#like_num').click(function(){
    	var post_id = $('#post_id').val();
    	var like = $('#like').val();
    	$.ajax({
    		type:'post',
    		url:'{BEESCRM::U('base/forum/doGetLike',array('forum_id' => $forum_id))}',
    		data:{'post_id':post_id,'like':like},
    		dataType:'json',
    		success:function(data){
    			if(data.status == 'S'){
    				like_num = $('#likenum').html();
    				if(data.like == 1){
    					$('#like').val(0);
    					$('#likenum').html(--like_num);
    					$('#like_num div').children().removeClass('isAction');
    				}else {
    					$('#like').val(1);
    					$('#likenum').html(++like_num);
    					$('#like_num div').children().addClass('isAction');
    				}
    				$.toast('success', data.message);
    			}else {
    				$.toast('error', data.message);
    			}
    		},
    		error:function(){
    			$.toast('error', '通讯错误');
    		},
    	});
    });
    
    <if condition="$data['self'] eq 'yes'">
    //删除吐槽信息
    $('.delete-btn').click(function(){
    	var post_id = $('#post_id').val();
    	//$.confirm('确定要删除？');
    	$.ajax({
    		type:'post',
    		url:'{BEESCRM::U('base/forum/doDelPost',array('forum_id' => $forum_id))}',
    		data:{'post_id':post_id,'cut_off':1},
    		dataType:'json',
    		success:function(data){
    			if(data.status == 'S'){
    				$.toast('success',data.message);
    				setTimeout(function(){
    					location.href = data.url;
    				},3000);
    			}else {
    				$.toast('error',data.message);
    			}
    		},
    		error:function(){
    			$.toast('error','通讯错误');
    		},
    	});
    });
    </if>
    
    //举报
    $('#report').click(function(){
    	var post_id = $('#post_id').val();
    	var url = '{BEESCRM::U('base/forum/report',array('forum_id' => $forum_id))}';
    	location.href = url + '/post_id/' + post_id;
    });
</script>
</body>
</html>